# -*- coding:utf-8 -*-
# @Time:2024/4/1921:01
# @Author:miuzg
# @FileName:new test2.py
# @Software:PyCharm

from selenium import webdriver
from selenium.webdriver.common.by import By
import time

url = 'https://www.taobao.com/'

driver = webdriver.Edge()

driver.get(url)

def scroll(driver,pause_time=2):
    # 获取初始页面高度
    height = driver.execute_script('return document.body.scrollHeight')

    while 1:
        # 滚动页面到底部
        driver.execute_script('window.scrollTo(0,document.body.scrollHeight)')

        # 等待页面加载
        time.sleep(pause_time)

        # 重新获取页面高度
        new_height = driver.execute_script('return document.body.scrollHeight')

        # 检查是否到达了页面的最底部，如果值一样就表示到底了，如果值不一样说明还能往下
        if new_height == height:
            break
        height = new_height

# 执行滚动
scroll(driver)

# 等待数据加载
time.sleep(3)

# 获取数据
div_list = driver.find_elements(By.XPATH,'//div[@class="tb-pick-content-item"]//span')

# 输出元素信息
print(len(div_list))

for div in div_list:
    print(div.text)
    print('-'*30)